********************************************************************************
****************            Table A10 and Table A11		              **************
********************************************************************************
use "C:\Users\junok\Dropbox\replication files\data sets\QSW_Undervaluation_Models_2022Nov23",clear
*use "C:\Users\quinnd\Dropbox\XR Politics\replication files\data sets\QSW_Undervaluation_Models_2022Nov23"

cd "C:\Users\junok\Dropbox\replication files\IO_Replication_July2023_JK\Part 3 Replication - July 2023"

********************************************************************************
drop if banking_center==1
drop if country=="Iraq"
drop if country=="El Salvador"
drop if country=="Mozambique"
drop if country=="Iran"
drop if country=="Syria" 
drop if country=="Lebanon"
drop if country=="Zimbabwe"
drop if wbcode=="BMU"
drop if wbcode=="VCT"
drop if wbcode=="LBR"

********************************************************************************
label var country "Country"
label var years "Year"
label var underval "Exchange Rate Undervaluation (Mean)"
label var wbcode "World Bank Country Code"
label var predict "Predict"
label var predict7089 "Predict"
label var predict9017 "Predict"
label var predict91 "Predict"
label var underval91 "Exchange Rate Unvervaluation_91"
label var lgrow9 "Log Growth"
label var balance9 "Trade/GDP Trade Balance"
label var popgr9 "Population Growth (mean)"
label var trade_gdp "Trade/GDP"
label var d1_d5 "Ratio between 1st Decile and 5th Decile"
label var ln_infl "Log Inflation (mean)"
label var inflation "Inflation (mean)"
label var inflation_gdpdeflator "Inflation GDP Deflator (mean)"
label var unemployment_ilo_est "Unemployment ILO Estimate (mean)"
label var unemployment_nat_est "Unemployment National Estimate (mean)"
label var capinnonresident "Capital Inflow Restrictions (mean)"
label var capoutresident "Capital Outflow Restrictions (mean)"
label var cap100 "Capital Account (mean)"
label var cur100 "Financial Current Account (mean)"
label var polity2 "Polity 2 (mean)"
label var polcomp "Political Competition (mean)"
label var resource_rents "Resource Rents"
label var mean_polity_g "Polity score (mean)"
label var mean_polcomp_g "Political Competition score (mean)"
label var exconst "Executive Constraints"
label var h_polcon3 "Political Constraints Index III"
label var fh_civ "Civil Liberties Rating (Freedom House)"
label var fh_pol "Political Rights Rating"
label var execrlc "Chief Executive Party Orientation"
label var pr "Proportional Representation"
label var worker "Worker Rights"
label var lvau "De Jure and De Facto Central Bank Independence Index unweighted"
label var lvaw "De Jure and De Facto Central Bank Independence Index weighted"
label var age_dependency_ratio "Age Dependency Ratio"
label var underval_sd "Standard Deviation Exchange Rate Undervaluation"
label var lgrow9_sd "Standard Deviation Log Growth"
label var index "Country group index"
label var polcomp_dummy "Political Competition (Dummy)"
label var polity2_4 "Polity2_4"
label var polity2_3 "Polity 2_3"
label var banking_center "Banking Center"
label var euro "Monetary Union"
label var EU "European Union membership"
label var ifscode "International Financial Statistics Database Country Code"
label var exchangerateregime_fine "Exchange Rate Regime Rheinart and Rogoff (Fine classification)"
label var exchangerateregime_coarse "Exchange Rate Regime (Coarse Classification)"
label var base "ifs code of base country"
label var range "Range of Exchange Rate Against Base (in percent)"
label var numzero "Months with zero change in exchange rate"
label var pegtype "Peg Type 1 = 0% change, 2 = 1% band, 3 = 2% band, 4 = 1 time deval/reval (Shambaugh)"
// label var peg "Standard Shambaugh 2004 classification (1= peg,0= nonpeg) (Shambaugh)"
label var peg "20221019 DQJK updated Shambaugh peg"
label var sypeg "Single Year Peg (Shambaugh)"
label var sypeg "Shambaugh Updated single year peg"
label var spegtype "Single Year Peg Type (same rules as pegtype) (Shambaugh)"
label var maxde "Largest (or most positive) % monthly change vs base (Shambaugh)"
label var minde "Smallest (or most negative) % monthly change vs base (Shambaugh)"
label var softpeg "Soft Peg Classification from OST AEJ-macro 2010 (Shambaugh)"
label var softpegtype "Soft Peg Type (Shambaugh)"
label var evol "Standard Deviation of Percentage Change in the Exchange Rate (Shambaugh)"
label var kspeg "Klein Shambaugh Classification (peg+sypeg - type 4) see JIE 2008"
label var oecd "OECD"
label var euro "20221019 DQJK updated euro"
label var peg_no_euro "pegnoeuro=1 if (peg==1 & euro==0) - 20221019 DQJK updated"



********************************************************************************

**# Bookmark #4

xtset index year, delta(5)

********************************************************************************
////////////////////////////////////////////////////////////////////////////////
****************                     Table A10                     **************
////////////////////////////////////////////////////////////////////////////////

pwcorr dunderval91 lpolity2 lpolcomp, sig

eststo clear

**********                        Polity2                             **********

**********                       1. Simple			   			      **********
eststo: xtreg d.underval91	l.polity2 , vce (cluster index)


**********                       2. Simple with Unit/Year FE	      **********
eststo: xtreg d.underval91 i.year   l.polity2 , fe vce (cluster index)


**********                    3. Y_{s-1} 				 			  **********
eststo: xtreg d.underval91  l.underval91  l.polity2 , vce (cluster index)




**********                        Polcomp                             **********

***********                    4. Simple				             ***********
eststo: xtreg d.underval91    l.polcomp, vce (cluster index)


***********     		5. Simple with Unit/Year FE    				************
eststo: xtreg d.underval91 i.year   l.polcomp , fe vce (cluster index)


*******     			6.Y_{s-1} 		 								*********       
eststo: xtreg d.underval91   l.underval91  l.polcomp, vce (cluster index)



esttab * using Table_A10.csv,  label b(3) se(3) scalar(r2_w r2_b r2_o N_clust) sfmt( a3 a0) star(* 0.1 ** 0.05 *** 0.01) replace
eststo clear 


**# Bookmark #3


//After updating euro peg peg_no_euro, we have different obs and countires in Table 5.
eststo clear
////////////////////////////////////////////////////////////////////////////////
****************                     Table A11                     **************
////////////////////////////////////////////////////////////////////////////////

***codes updated 31 july 2023 omitting euro entirely
eststo clear
**********                        Polity2                             **********

**********              1. Simple OLS	with Unit/Year FE   		  **********
eststo: xtreg d.underval91   i.year  l.polity2              l.peg  l.lnrealgdp9 l.lgrow9  l.balance9 l.ltrade9 l.inflation  age   , fe vce (cluster index)


**********              2. Y_{s-1} 		  **********
eststo: xtreg d.underval91   i.year  l.polity2 l.underval91 l.peg  l.lnrealgdp9 l.lgrow9  l.balance9 l.ltrade9 l.inflation age  , vce (cluster index)


**********              3. Polity2 IV 		  **********
eststo: xi: ivreg2 d.underval91 i.year l.underval91         l.peg  l.lnrealgdp9 l.lgrow9  l.balance9 l.ltrade9 l.inflation age  (l.polity2= l.mean_polity_g l2.mean_polity_g l3.mean_polity_g) , first cluster(index) savefirst savefprefix(f1)


//Perseran R2 IV: .13854374
di 1-[( `e(rss)'/(`e(N)'-`e(df_m)'))/((`e(rss)'+`e(mss)')/(`e(N)'-1))]
//Kleibergen-Paap rk LM statistic: 80.603
//(Kleibergen-Paap rk Wald F statistic):       2834.441
//Stock-Yogo weak ID test critical values:  5% maximal IV relative bias    13.91
//Stock-Yogo weak ID test critical values:  10% maximal IV relative bias   9.08
//Hansen J statistic Chi-sq(2) P-val =    0.4773


**********                        Polcomp                             **********

**********              4. Simple OLS	with Unit/Year FE   		  **********
eststo: xtreg d.underval91   i.year   l.polcomp              l.peg l.lnrealgdp9 l.lgrow9  l.balance9 l.ltrade9 l.inflation  age , fe vce (cluster index)

**********              5. Y_{s-1} 		  **********
eststo: xtreg d.underval91   i.year  l.polcomp l.underval91  l.peg l.lnrealgdp9 l.lgrow9  l.balance9 l.ltrade9 l.inflation  age , vce (cluster index)

**********              6. Polcomp IV 		  **********
eststo: xi: ivreg2 d.underval91 i.year l.underval91          l.peg l.lnrealgdp9 l.lgrow9  l.balance9 l.ltrade9 l.inflation  age (l.polcomp= l.mean_polcomp_g l2.mean_polcomp_g l3.mean_polcomp_g) , first cluster(index) savefirst savefprefix(f2)

// Pesaran IV r-squared: di 1-[( `e(rss)'/(`e(N)'-`e(df_m)'))/((`e(rss)'+`e(mss)')/(`e(N)'-1))]
// here's the cite : Pesaran, M. Hashem, and Richard J. Smith. 1994. A Generalized R2 Criterion for Regression Models Estimated by the Instrumental Variables Method. Econometrica 62 (3):705–10


//Perseran R2 IV: .15085651
di 1-[( `e(rss)'/(`e(N)'-`e(df_m)'))/((`e(rss)'+`e(mss)')/(`e(N)'-1))]
//Kleibergen-Paap rk LM statistic:  64.179
//(Kleibergen-Paap rk Wald F statistic):         23.008
//Stock-Yogo weak ID test critical values:  5% maximal IV relative bias    13.91
//Stock-Yogo weak ID test critical values:  10% maximal IV relative bias     9.08
//Hansen J statistic Chi-sq(2) P-val =    0.6531


**********             7. Euro Zone Omitted		  **********
eststo: xtreg d.underval91   i.year l.polcomp l.underval91  l.peg  l.lnrealgdp9 l.lgrow9  l.balance9 l.ltrade9 l.inflation                   age if monetary!=1  , vce (cluster index)

**********           8. Polcomp x peg_no_euro **********************
eststo: xtreg d.underval91   i.year c.l.polcomp##c.l.peg    l.underval91   l.lnrealgdp9 l.lgrow9  l.balance9 l.ltrade9 l.inflation   age     , vce (cluster index)

***figure A30
margins, at(l.polcomp=(1 (.5) 10) l.peg=( 0 1))
marginsplot, title("Polcomp's Average Effect on Valuation") subtitle("Peg=Red No Peg = Blue; no Euro") ytitle("Estimated Effect on Currency Valuation Given Polcomp") recast(line) recastci(rline) ciopts(lpattern(shortdash)) xsc(titlegap(5)) ysc(titlegap(5)) scheme(s2color) graphregion(color(white)) xtitle("Polcomp")  legend(off) yline(0) addplot( hist polcomp if e(sample) & polcomp>0 , width(.25) percent mfcolor(none) fcolor(none) lcolor(gs10) yaxis(2) yscale(alt axis(2)) xscale(range(1 10)) xlabel(1 (.5) 10) )


esttab * using Table_A11.csv , replace label  compress b(%9.3f) se(3) starlevels(* 0.10 ** 0.05 *** 0.01) sca(N N_clust r2_w r2_o) sfmt(%9.0f %9.0f %9.3f ) nomtitles  nonotes noobs 


